<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/icon-font.css"/><!--图标-->
    <link rel="stylesheet" href="../../css/info-list.css"/><!--资讯列表-->
    <link rel="stylesheet" href="../../css/report-list.css"/><!--研报列表-->
    <link rel="stylesheet" href="../../plugin/mescroll/css/mescroll.min.css">

    <title>搜索</title>
    <style>

        em {
            color: #2C68FF;
            font-style: initial;
        }

        .index-search-wrap {
            padding: 0 .32rem;
            background: rgba(255, 255, 255, 1);
        }

        .index-search-box {
            margin-bottom: .12rem;
            margin-top: .12rem;
        }

        .index-search-img {
            width: 7.5rem;
            height: 3rem;
        }

        .index-search-img img {
            width: 100%;
            height: 100%;
        }

        .index-search-search {
            height: .64rem;
            width: 6.08rem;
            border-radius: .08rem;
            background: rgba(245, 245, 245, 1);
        }

        .index-search-icon {
            margin-left: .24rem;
            color: rgba(159, 159, 159, 1);
        }

        .index-search-sc {
            color: rgba(159, 159, 159, 1);
            height: .64rem;
            width: .92rem;
            line-height: .64rem;
            margin: auto;
            text-align: center;
        }


        .index-search-search i {
            margin-right: .26rem;
        }

        .index-search-search input {
            margin-left: .14rem;
            line-height: .6rem;
        }

        input[type=search]::-webkit-search-cancel-button {
            -webkit-appearance: none;
        }

        .index-search-cancle {
            color: rgba(44, 104, 255, 1);
        }


        .search-industry-list {
            flex-wrap: wrap;
            display: flex;
            padding: 0 .18rem .2rem .18rem;
            border-bottom: solid 1px #f6f6f6;
        }

        .research-industry-item {
            width: 2.1rem;
            height: 1.64rem;
            background: rgba(253, 253, 253, 1);
            border-radius: 4px;
            margin: .2rem .14rem 0 .14rem;
            border: 1px solid rgba(240, 240, 240, 1);
        }

        .research-industry-item img {
            width: .64rem;
            height: .64rem;
            margin-bottom: .04rem;
        }

        .research-industry-item div {
            line-height: .4rem;
            width: 100%;
            text-align: center;
        }


    </style>
</head>
<body>

<div class="flex-column h-100-p ff400">

    <!--状态栏-->
    <div class="placeholder-top">
        <!--状态栏-->
        <div class="bg-main status-bar pos-f"></div>
        <!--导航栏-->
        <div class="bg-main nav-bar pos-f flex-row justify-content-between c-white align-items-center">
            <div class="left-bar" onclick="clickBack()">
                <span class="iconfont iconfanhui1 fs16"></span>
            </div>
            <div class="center-bar fs16 ff500 line1"></div>
            <div class="right-bar">
            </div>
        </div>
    </div>

    <div id="mescroll" class="flex-1 mescroll">
        <!--产业链-->
        <div class="search-industry-list bg-white"></div>
    </div>

</div>

</body>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/dict.js"></script>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/checkJsBridge.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/api.js"></script>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/date.js"></script>
<script src="../../js/icon-font.js"></script><!--用于彩色字体图标-->
<script src="../../js/template.js"></script>

<script src="../../plugin/mescroll/js/mescroll.min.js"></script>

<script>
  let meScroll
  let pm = {
    lastDttm: DateUtils.getNowInt(),
    pageNum: 1,
    pageSize: 20,
    isScroll: true,
    keyWord: '',
  }

  function initPage(params) {
    //状态栏自适应
    Utils.sbhAdaptive()

    pm.keyWord = decodeURIComponent(params.key)

    jsBridge.callBridge('setTitle', {title: params.title})
    $('.center-bar').html(params.title)

    //下拉刷新、滚动加载
    meScroll = Template.createMeScroll({
      id: 'mescroll', //区域ID
      pageNum: pm.pageNum,
      downCallback: reLoadPage, //下拉刷新入口
      upCallback: goSearch //滚动加载入口
    })

  }

  function reLoadPage() {
    pm.isScroll = false//初始化滚动状态
    pm.pageNum = 1
    pm.lastDttm = DateUtils.getNowInt()

    goSearch()
  }

  //搜索入口
  //搜索产业链
  function goSearch() {
    Server.industrialChain.getIndustrialChain({
      pageNum: pm.pageNum,
      pageSize: pm.pageSize,
      key: pm.keyWord
    }).then(function (data) {
      let htmlStr = ''
      let len = 0

      if (data.indList) {
        len = data.indList.length
        //产业链
        $.each(data.indList, function (k, obj) {
          htmlStr += '<div class="flex-column justify-content-center align-items-center research-industry-item" onclick="goIndustrialDetail(\'' + obj.industrialCode + '\',\'' + obj.industrialName + '\')">\n' +
                '                    <img src="' + obj.coverImgUrl + '">\n\n' +
                '                    <div class="line1">' + dealKeyWord(obj.industrialName) + '</div>\n' +
                '                </div>'
        })

        if (pm.pageNum === 1) {
          $('.search-industry-list').html(htmlStr)
        } else {
          $('.search-industry-list').append(htmlStr)
        }
      }
      pm.pageNum ++

      //下拉刷新结束回调
      meScroll.endSuccess(len, len === pm.pageSize)
    }).catch((error) => {
      meScroll.endErr()
    })

    function dealKeyWord(desc) {
      if (desc && pm.keyWord) {
        desc = desc.replace(pm.keyWord, '<em>' + pm.keyWord + '</em>')
      }
      return desc
    }

    //搜索词缓存
    if (pm.keyWord) {
      Template.searchWordCache(pm.keyWord)
    }
  }

  //跳转到产业链详情
  function goIndustrialDetail(code, name) {
    jsBridge.openWindow('html/research/industrial-detail.html?menuCode=' + code + '&name=' + name, {}, {noBar: false})
  }

</script>
</html>
